package com.los.rabbitmq.subscribe;


import com.los.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: rabbitmq
 * @description: 订阅模式-发布消息
 * @author: Yujuan
 * @create: 2018-08-02 11:45
 **/
public class Send {
    private static final String EXCHANGE_NAME="los_exchange_fanout";
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection= ConnectionUtils.getConnection();
        Channel channel=connection.createChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");//分发
        //发送消息
        String msg="Hello Los";

        channel.basicPublish(EXCHANGE_NAME,"",null,msg.getBytes());
        System.out.println("Send:"+msg);

        channel.close();
        connection.close();
    }
}
